package com.simple.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.simple.entity.SysRole;
import com.simple.entity.vo.SysRoleVo;

import java.util.List;

public interface SysRoleRepository extends JpaRepository<SysRole,Integer> {
    @Query(value="select * from  sys_role  where id=?1",nativeQuery=true)
    public SysRole findByRoleId(Integer id);

    @Query(value="SELECT b.menu_id FROM  sys_user a LEFT JOIN sys_role b ON a.role_id=b.id  WHERE a.username=?1",nativeQuery=true)
    public String findMenuByUserName(String username);

    @Query(value="SELECT a.id as id,a.menu_id as menuId,a.role_name as roleName,GROUP_CONCAT(b.username) AS users  FROM sys_role a LEFT JOIN sys_user  b ON  b.role_id=a.id   WHERE a.del_status=0 GROUP BY a.role_name",nativeQuery=true)
    public List<SysRoleVo> findAllRoles();

    @Query(value="SELECT *FROM sys_role WHERE del_status=0",nativeQuery = true)
    public List<SysRole> findAll();

    @Modifying
    @Query(value="update  sys_role set del_status=1   WHERE  id=?1" ,nativeQuery=true)
    public void deleteById(Integer id);

}
